package bishi.bilibili;

import java.util.*;

/**
 * @Classname Main1
 * @Description TODO
 * @Date 2021/9/13 19:23
 * @Created by ASUS
 */
public class Main1 {
    public static int[][] getMatrix() {
        Scanner scanner = new Scanner(System.in);
        List<String> rows = new ArrayList<>();
        String t;
        while (scanner.hasNextLine()) {
            t = scanner.nextLine().trim();
            if (t.endsWith("]]")) break;
            rows.add(t);
        }
        scanner.close();
//        rows.forEach(System.out::println);
        String s = rows.get(0);
        String[] split = s.substring(2, s.length() - 2).split(",");
        int[][] matrix = new int[rows.size()][split.length];
        for (int i = 0; i < split.length; i++) {
            matrix[0][i] = Integer.parseInt(split[i]);
        }
        for (int i = 1; i < rows.size(); i++) {
            s = rows.get(i);
            split = s.substring(1, s.length() - 2).split(",");
            for (int j = 0; j < split.length; j++) {
                matrix[i][j] = Integer.parseInt(split[j]);
            }
        }
//        Arrays.stream(matrix).forEach(a -> System.out.println(Arrays.toString(a)));

        return matrix;
    }

    static int max = 0;
    static boolean[][] v;
    static int[][] dirs = new int[][]{{0, -1}, {0, 1}, {-1, 0}, {1, 0}};

    public static void main(String[] args) {
        int[][] matrix = getMatrix();
        v = new boolean[matrix.length][matrix[0].length];
        for (int i = 0; i < matrix.length; i++) {
            for (int j = 0; j < matrix[0].length; j++) {
                if (matrix[i][j] == 1) max = Math.max(bfs(matrix, i, j), max);
            }
        }
//        Arrays.stream(v).forEach(a -> System.out.println(Arrays.toString(a)));
        System.out.println(max);
    }

    private static int bfs(int[][] matrix, int x, int y) {
        if (v[x][y]) return 0;
        int amount = 0;
        Queue<int[]> q = new ArrayDeque<>();
        v[x][y] = true;
        q.offer(new int[]{x, y});
        while (!q.isEmpty()) {
            int size = q.size();
            for (int i = 0; i < size; i++) {
                int[] node = q.poll();
                assert node != null;
                amount++;
                for (int[] dir : dirs) {
                    int dx = node[0] + dir[0], dy = node[1] + dir[1];
                    if (dx < 0 || dx > matrix.length - 1) continue;
                    if (dy < 0 || dy > matrix[0].length - 1) continue;
                    if (!v[dx][dy] && matrix[dx][dy] == 1) {
                        q.offer(new int[]{dx, dy});
                        v[dx][dy] = true;
                    }
                }
            }
        }
        return amount;
    }
}
